<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>entrypointregistry.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_debug_entrypointregistry.js.html">entrypointregistry.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2010 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview A global registry for entry points into a program,
<a name="line17"></a> * so that they can be instrumented. Each module should register their
<a name="line18"></a> * entry points with this registry. Designed to be compiled out
<a name="line19"></a> * if no instrumentation is requested.
<a name="line20"></a> *
<a name="line21"></a> * Entry points may be registered before or after a call to
<a name="line22"></a> * goog.debug.entryPointRegistry.monitorAll. If an entry point is registered
<a name="line23"></a> * later, the existing monitor will instrument the new entry point.
<a name="line24"></a> *
<a name="line25"></a> * @author nicksantos@google.com (Nick Santos)
<a name="line26"></a> */
<a name="line27"></a>
<a name="line28"></a>goog.provide(&#39;goog.debug.EntryPointMonitor&#39;);
<a name="line29"></a>goog.provide(&#39;goog.debug.entryPointRegistry&#39;);
<a name="line30"></a>
<a name="line31"></a>goog.require(&#39;goog.asserts&#39;);
<a name="line32"></a>
<a name="line33"></a>
<a name="line34"></a>
<a name="line35"></a>/**
<a name="line36"></a> * @interface
<a name="line37"></a> */
<a name="line38"></a>goog.debug.EntryPointMonitor = function() {};
<a name="line39"></a>
<a name="line40"></a>
<a name="line41"></a>/**
<a name="line42"></a> * Instruments a function.
<a name="line43"></a> *
<a name="line44"></a> * @param {!Function} fn A function to instrument.
<a name="line45"></a> * @return {!Function} The instrumented function.
<a name="line46"></a> */
<a name="line47"></a>goog.debug.EntryPointMonitor.prototype.wrap;
<a name="line48"></a>
<a name="line49"></a>
<a name="line50"></a>/**
<a name="line51"></a> * Try to remove an instrumentation wrapper created by this monitor.
<a name="line52"></a> * If the function passed to unwrap is not a wrapper created by this
<a name="line53"></a> * monitor, then we will do nothing.
<a name="line54"></a> *
<a name="line55"></a> * Notice that some wrappers may not be unwrappable. For example, if other
<a name="line56"></a> * monitors have applied their own wrappers, then it will be impossible to
<a name="line57"></a> * unwrap them because their wrappers will have captured our wrapper.
<a name="line58"></a> *
<a name="line59"></a> * So it is important that entry points are unwrapped in the reverse
<a name="line60"></a> * order that they were wrapped.
<a name="line61"></a> *
<a name="line62"></a> * @param {!Function} fn A function to unwrap.
<a name="line63"></a> * @return {!Function} The unwrapped function, or {@code fn} if it was not
<a name="line64"></a> *     a wrapped function created by this monitor.
<a name="line65"></a> */
<a name="line66"></a>goog.debug.EntryPointMonitor.prototype.unwrap;
<a name="line67"></a>
<a name="line68"></a>
<a name="line69"></a>/**
<a name="line70"></a> * An array of entry point callbacks.
<a name="line71"></a> * @type {!Array.&lt;function(!Function)&gt;}
<a name="line72"></a> * @private
<a name="line73"></a> */
<a name="line74"></a>goog.debug.entryPointRegistry.refList_ = [];
<a name="line75"></a>
<a name="line76"></a>
<a name="line77"></a>/**
<a name="line78"></a> * Monitors that should wrap all the entry points.
<a name="line79"></a> * @type {!Array.&lt;!goog.debug.EntryPointMonitor&gt;}
<a name="line80"></a> * @private
<a name="line81"></a> */
<a name="line82"></a>goog.debug.entryPointRegistry.monitors_ = [];
<a name="line83"></a>
<a name="line84"></a>
<a name="line85"></a>/**
<a name="line86"></a> * Whether goog.debug.entryPointRegistry.monitorAll has ever been called.
<a name="line87"></a> * Checking this allows the compiler to optimize out the registrations.
<a name="line88"></a> * @type {boolean}
<a name="line89"></a> * @private
<a name="line90"></a> */
<a name="line91"></a>goog.debug.entryPointRegistry.monitorsMayExist_ = false;
<a name="line92"></a>
<a name="line93"></a>
<a name="line94"></a>/**
<a name="line95"></a> * Register an entry point with this module.
<a name="line96"></a> *
<a name="line97"></a> * The entry point will be instrumented when a monitor is passed to
<a name="line98"></a> * goog.debug.entryPointRegistry.monitorAll. If this has already occurred, the
<a name="line99"></a> * entry point is instrumented immediately.
<a name="line100"></a> *
<a name="line101"></a> * @param {function(!Function)} callback A callback function which is called
<a name="line102"></a> *     with a transforming function to instrument the entry point. The callback
<a name="line103"></a> *     is responsible for wrapping the relevant entry point with the
<a name="line104"></a> *     transforming function.
<a name="line105"></a> */
<a name="line106"></a>goog.debug.entryPointRegistry.register = function(callback) {
<a name="line107"></a>  // Don&#39;t use push(), so that this can be compiled out.
<a name="line108"></a>  goog.debug.entryPointRegistry.refList_[
<a name="line109"></a>      goog.debug.entryPointRegistry.refList_.length] = callback;
<a name="line110"></a>  // If no one calls monitorAll, this can be compiled out.
<a name="line111"></a>  if (goog.debug.entryPointRegistry.monitorsMayExist_) {
<a name="line112"></a>    var monitors = goog.debug.entryPointRegistry.monitors_;
<a name="line113"></a>    for (var i = 0; i &lt; monitors.length; i++) {
<a name="line114"></a>      callback(goog.bind(monitors[i].wrap, monitors[i]));
<a name="line115"></a>    }
<a name="line116"></a>  }
<a name="line117"></a>};
<a name="line118"></a>
<a name="line119"></a>
<a name="line120"></a>/**
<a name="line121"></a> * Configures a monitor to wrap all entry points.
<a name="line122"></a> *
<a name="line123"></a> * Entry points that have already been registered are immediately wrapped by
<a name="line124"></a> * the monitor. When an entry point is registered in the future, it will also
<a name="line125"></a> * be wrapped by the monitor when it is registered.
<a name="line126"></a> *
<a name="line127"></a> * @param {!goog.debug.EntryPointMonitor} monitor An entry point monitor.
<a name="line128"></a> */
<a name="line129"></a>goog.debug.entryPointRegistry.monitorAll = function(monitor) {
<a name="line130"></a>  goog.debug.entryPointRegistry.monitorsMayExist_ = true;
<a name="line131"></a>  var transformer = goog.bind(monitor.wrap, monitor);
<a name="line132"></a>  for (var i = 0; i &lt; goog.debug.entryPointRegistry.refList_.length; i++) {
<a name="line133"></a>    goog.debug.entryPointRegistry.refList_[i](transformer);
<a name="line134"></a>  }
<a name="line135"></a>  goog.debug.entryPointRegistry.monitors_.push(monitor);
<a name="line136"></a>};
<a name="line137"></a>
<a name="line138"></a>
<a name="line139"></a>/**
<a name="line140"></a> * Try to unmonitor all the entry points that have already been registered. If
<a name="line141"></a> * an entry point is registered in the future, it will not be wrapped by the
<a name="line142"></a> * monitor when it is registered. Note that this may fail if the entry points
<a name="line143"></a> * have additional wrapping.
<a name="line144"></a> *
<a name="line145"></a> * @param {!goog.debug.EntryPointMonitor} monitor The last monitor to wrap
<a name="line146"></a> *     the entry points.
<a name="line147"></a> * @throws {Error} If the monitor is not the most recently configured monitor.
<a name="line148"></a> */
<a name="line149"></a>goog.debug.entryPointRegistry.unmonitorAllIfPossible = function(monitor) {
<a name="line150"></a>  var monitors = goog.debug.entryPointRegistry.monitors_;
<a name="line151"></a>  goog.asserts.assert(monitor == monitors[monitors.length - 1],
<a name="line152"></a>      &#39;Only the most recent monitor can be unwrapped.&#39;);
<a name="line153"></a>  var transformer = goog.bind(monitor.unwrap, monitor);
<a name="line154"></a>  for (var i = 0; i &lt; goog.debug.entryPointRegistry.refList_.length; i++) {
<a name="line155"></a>    goog.debug.entryPointRegistry.refList_[i](transformer);
<a name="line156"></a>  }
<a name="line157"></a>  monitors.length--;
<a name="line158"></a>};
</pre>


</body>
</html>
